package com.haois.mp.database.util.jx;

import java.io.Serializable;

/**
 * 分页
 */
public class Pager implements Serializable {

    private int currentPage = 1;
    private int pageSize = 10;
    private long totalSize = 0;
    private int totalPage = 1;

    private boolean hasFirst;
    private boolean hasPrevious;
    private boolean hasNext;
    private boolean hasLast;

    public Pager() {
    }

    public Pager(int currentPage, int pageSize, long totalSize, int totalPage, boolean hasFirst, boolean hasPrevious, boolean hasNext, boolean hasLast) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalSize = totalSize;
        this.totalPage = totalPage;
        this.hasFirst = hasFirst;
        this.hasPrevious = hasPrevious;
        this.hasNext = hasNext;
        this.hasLast = hasLast;
    }

    public int getCurrentPage() {
        return currentPage;
    }


    public void setCurrentPage(String currentPage) {
        try {
            int page = Integer.parseInt(currentPage);
            if (page > 0)
                this.currentPage = page;
        } catch (Exception e) {
        }
    }

    public boolean getHasLast() {
        return currentPage == getTotalPage() ? false : true;
    }

    public boolean getHasNext() {
        return getHasLast() ? true : false;
    }

    public int getPageSize() {
        return pageSize;
    }


    public void setPageSize(String pageSize) {
        try {
            int size = Integer.parseInt(pageSize);
            if (size > 0 && size < 1000)
                this.pageSize = size;
        } catch (Exception e) {
        }
    }

    public int getTotalPage() {
        totalPage = (int) (totalSize / pageSize);
        if (totalSize % pageSize != 0)
            totalPage++;
        totalPage = totalPage == 0 ? 1 : totalPage;
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        if (totalSize > -1)
            this.totalSize = totalSize;
        currentPage = currentPage > getTotalPage() ? getTotalPage()
                : currentPage;
    }


    public boolean isHasFirst() {
        return hasFirst;
    }

    public void setHasFirst(boolean hasFirst) {
        this.hasFirst = hasFirst;
    }

    public boolean isHasPrevious() {
        return hasPrevious;
    }

    public void setHasPrevious(boolean hasPrevious) {
        this.hasPrevious = hasPrevious;
    }


    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }



    public void setHasLast(boolean hasLast) {
        this.hasLast = hasLast;
    }
}